package com.zust513.mapper;

import com.zust513.entity.Region;
import com.zust513.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface IUserMapper {
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户列表
     */
     @Select("SELECT * FROM users WHERE username = #{username}")
    List<User> getUsersByUserName(String username);


    /**
     * 注册用户
     * @param user 用户信息
     */
    @Insert("INSERT INTO users (username, password_hash, role,phone,email, status, created_at) VALUES (#{username}, #{passwordHash}, #{role}, #{phone},#{email},#{status}, #{createdAt})")
    void registerUser(User user);

    /**
     * 根据用户名和密码查询用户
     * @param username 用户名
     * @return 用户对象
     */
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findUserByUsername(String username);

    /**
     * 添加账户
     * @param userId 用户ID
     */
    @Insert("INSERT INTO accounts (user_id,balance,total_recharge,total_expense) VALUES (#{userId},0,0,0)")
    void addAccounts(Integer userId);


    /**
     * 添加快递员
     * @param userId 用户ID
     */
    @Insert("INSERT INTO couriers (courier_id,user_id,total_orders,current_status,audit_status) VALUES (#{userId},#{userId},0,'offline','pending')")
    void addCourier(Integer userId);

    /**
     * 添加快递员和区域
     * @param userId 用户ID
     * @param regionId 区域ID
     */
    @Insert("INSERT INTO courier_regions (courier_id,region_id) VALUES (#{userId},#{regionId})")
    void addCourierAndRegion(int userId, int regionId);

    /**
     * 获取所有快递员的配送区域
     * @return 配送区域列表
     */
    @Select("SELECT region_id,name FROM regions ")
    List<Region> getDeliveryAreas();
}
